home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
8206
/
8206.xpi
/
content
/
rss
/
rss.js
< prev
next >
Wrap
Text File
|
2010-02-02
|
4KB
|
162 lines
WiseStampRSSFeed.prototype = new Object();
WiseStampRSSFeed.prototype.fetch = WiseStampRSSFeed_fetch;
WiseStampRSSFeed.prototype.parse = WiseStampRSSFeed_parse;
WiseStampRSSFeed.prototype.parseAtom = WiseStampRSSFeed_parseAtom;
WiseStampRSSFeed.prototype.parseAtomItem = WiseStampRSSFeed_parseAtomItem;
WiseStampRSSFeed.prototype.parseRSS2 = WiseStampRSSFeed_parseRSS2;
WiseStampRSSFeed.prototype.parseRSS2Item = WiseStampRSSFeed_parseRSS2Item;
function WiseStampRSSFeed(url)
{
this.url = url;
}
function WiseStampRSSFeed_fetch(callback, failure)
{
WiseStampUtils.log("rss.js :: WiseStampRSSFeed_fetch >>>>>");
var feed = this;
var request = WiseStampCreateXMLHttpRequest();
request.onsuccess = function ()
{
WiseStampUtils.log("rss.js :: WiseStampRSSFeed_fetch :: onSuccess");
//dump("Success:"); dump(this.url); dump("\n");
if (!request.responseXML)
{
WiseStampUtils.log("rss.js :: WiseStampRSSFeed_fetch :: error - no responseXML");
callback(new WiseStampRSSData());
return;
};
callback(feed.parse(request.responseXML));
};
request.onfailure = function ()
{
WiseStampUtils.log("rss.js :: WiseStampRSSFeed_fetch :: onFailure");
//dump("Failure:"); dump(this.url); dump("\n");
callback(new WiseStampRSSData());
};
request.open('GET', this.url, 1);
request.send('');
}
function WiseStampRSSFeed_parse(xml)
{
WiseStampUtils.log("rss.js :: WiseStampRSSFeed_parse >>>>>");
// RSS x.xx
var rss = xml.getElementsByTagName('rss')[0];
if (rss)
{
var version = rss.getAttribute('version');
switch (parseFloat(version))
{
case 2:
return this.parseRSS2(rss);
};
return this.parseRSS2(rss);
};
// RSS 1.00
var root = xml.documentElement;
if (root && root.tagName == "rdf:RDF" && root.getAttribute("xmlns") == "http://purl.org/rss/1.0/")
{
return this.parseRSS2(root);
};
// ATOM
var feed = xml.getElementsByTagName('feed')[0];
if (feed)
{
return this.parseAtom(feed);
};
return new WiseStampRSSData();
}
function WiseStampRSSFeed_parseAtom(rss)
{
var data = new WiseStampRSSData();
var itemNodes = rss.getElementsByTagName('entry');
for (var i = 0; i < itemNodes.length; i++)
{
var itemNode = itemNodes[i];
data.addItem(this.parseAtomItem(itemNode));
};
return data;
}
function WiseStampRSSFeed_parseAtomItem(itemNode)
{
var item = new WiseStampRSSDataItem();
for (var i = 0; i < itemNode.childNodes.length; i++)
{
var childNode = itemNode.childNodes[i];
switch (childNode.tagName)
{
case "title":
item.setTitle(childNode.textContent);
break;
case "link":
if (childNode.getAttribute("rel") == "alternate")
{
item.setLink(childNode.getAttribute("href"));
};
break;
case "published":
item.setPubDate(Date.parse(childNode.textContent));
break;
};
};
return item;
}
function WiseStampRSSFeed_parseRSS2(rss)
{
WiseStampUtils.log("rss.js :: WiseStampRSSFeed_parseRSS2 >>>>>");
var data = new WiseStampRSSData();
var itemNodes = rss.getElementsByTagName('item');
for (var i = 0; i < itemNodes.length; i++)
{
var itemNode = itemNodes[i];
data.addItem(this.parseRSS2Item(itemNode));
};
return data;
}
function WiseStampRSSFeed_parseRSS2Item(itemNode)
{
WiseStampUtils.log("rss.js :: WiseStampRSSFeed_parseRSS2Item >>>>>");
var item = new WiseStampRSSDataItem();
for (var i = 0; i < itemNode.childNodes.length; i++)
{
var childNode = itemNode.childNodes[i];
switch (childNode.tagName)
{
case "title":
item.setTitle(childNode.textContent);
break;
case "link":
item.setLink(childNode.textContent);
break;
case "pubDate":
item.setPubDate(Date.parse(childNode.textContent));
break;
};
};
return item;
}